import { get, post } from '@/utils/request'

// 伤病报告相关接口

/**
 * 伤病报告查询参数
 */
export interface InjuryReportQueryParams {
  current?: number
  size?: number
  keyword?: string
  startDate?: string
  endDate?: string
  severity?: string
  status?: string
}

/**
 * 伤病报告详情
 */
export interface InjuryReport {
  id: number
  userId: number
  username: string
  title: string
  bodyPart: string
  severity: string
  description: string
  status: string
  injuryTime: string
  createdAt: string
  diagnosis?: string
  treatment?: string
}

/**
 * 伤病报告统计数据
 */
export interface InjuryReportStats {
  totalCount: number
  severityStats: Record<string, number>
  statusStats: Record<string, number>
  monthlyStats: Record<string, number>
}

/**
 * 诊断与治疗建议请求
 */
export interface DiagnosisRequest {
  reportId: number
  diagnosis: string
  treatment: string
  status: string
  userId: number
}

/**
 * 获取所有伤病报告列表
 */
export function getInjuryReports(params: InjuryReportQueryParams) {
  return get<{
    records: InjuryReport[]
    total: number
    size: number
    current: number
  }>('/injury/admin/report/list', params as unknown as Record<string, unknown>)
}

/**
 * 添加诊断和治疗建议
 */
export function addDiagnosis(data: DiagnosisRequest) {
  return post<boolean>('/injury/admin/report/diagnosis', data as unknown as Record<string, unknown>)
}

/**
 * 获取伤病报告统计数据
 */
export function getInjuryReportStats(params: { startDate?: string; endDate?: string }) {
  return get<InjuryReportStats>('/injury/admin/report/stats', params)
}

/**
 * 批量导出伤病报告
 */
export function exportInjuryReports(params: {
  ids?: string
  startDate?: string
  endDate?: string
  severity?: string
}) {
  return post<string>('/injury/admin/report/export', params)
}

// 评估预约相关接口

/**
 * 评估预约查询参数
 */
export interface AppointmentQueryParams {
  teacherId?: number
  status?: string
  current?: number
  size?: number
}

/**
 * 线下评估预约详情
 */
export interface OfflineAppointment {
  id: number
  reportId: number
  studentId: number
  studentName: string
  appointmentDate: string
  appointmentTime: string
  location: string
  status: string
  studentNote: string
  createdAt: string
  teacherNote?: string
  feedback?: string
}

/**
 * 线上评估预约详情
 */
export interface OnlineAppointment {
  id: number
  reportId: number
  studentId: number
  studentName: string
  appointmentDate: string
  appointmentTime: string
  duration: number
  platform: string
  status: string
  studentNote: string
  createdAt: string
  meetingUrl?: string
  meetingId?: string
  meetingPassword?: string
  feedback?: string
}

/**
 * 评估统计数据
 */
export interface AssessmentStats {
  totalOfflineCount: number
  totalOnlineCount: number
  totalCount: number
  offlineStatusStats: Record<string, number>
  onlineStatusStats: Record<string, number>
  dateStats: Record<string, number>
}

/**
 * 线下评估审核请求
 */
export interface OfflineAppointmentReviewRequest {
  appointmentId: number
  teacherId: number
  approved: boolean
  teacherNote?: string
  rejectReason?: string
}

/**
 * 线下评估完成请求
 */
export interface OfflineAppointmentCompleteRequest {
  appointmentId: number
  teacherId: number
  feedback: string
}

/**
 * 线上评估审核请求
 */
export interface OnlineAppointmentReviewRequest {
  appointmentId: number
  teacherId: number
  approved: boolean
  meetingUrl?: string
  meetingId?: string
  meetingPassword?: string
  rejectReason?: string
}

/**
 * 线上评估完成请求
 */
export interface OnlineAppointmentCompleteRequest {
  appointmentId: number
  teacherId: number
  feedback: string
}

/**
 * 获取线下评估预约列表
 */
export function getOfflineAppointments(params: AppointmentQueryParams) {
  return get<{
    records: OfflineAppointment[]
    total: number
    size: number
    current: number
  }>('/assessment/admin/offline/pending', params as unknown as Record<string, unknown>)
}

/**
 * 审核线下评估预约
 */
export function reviewOfflineAppointment(data: OfflineAppointmentReviewRequest) {
  return post<boolean>(
    '/assessment/admin/offline/review',
    data as unknown as Record<string, unknown>,
  )
}

/**
 * 完成线下评估
 */
export function completeOfflineAppointment(data: OfflineAppointmentCompleteRequest) {
  return post<boolean>(
    '/assessment/admin/offline/complete',
    data as unknown as Record<string, unknown>,
  )
}

/**
 * 获取线上评估预约列表
 */
export function getOnlineAppointments(params: AppointmentQueryParams) {
  return get<{
    records: OnlineAppointment[]
    total: number
    size: number
    current: number
  }>('/assessment/admin/online/pending', params as unknown as Record<string, unknown>)
}

/**
 * 审核线上评估预约
 */
export function reviewOnlineAppointment(data: OnlineAppointmentReviewRequest) {
  return post<boolean>(
    '/assessment/admin/online/review',
    data as unknown as Record<string, unknown>,
  )
}

/**
 * 完成线上评估
 */
export function completeOnlineAppointment(data: OnlineAppointmentCompleteRequest) {
  return post<boolean>(
    '/assessment/admin/online/complete',
    data as unknown as Record<string, unknown>,
  )
}

/**
 * 获取评估统计数据
 */
export function getAssessmentStats(params: { startDate?: string; endDate?: string }) {
  return get<AssessmentStats>('/assessment/admin/stats', params)
}
